﻿using Microsoft.EntityFrameworkCore;

namespace System.Repository.Base
{
    public interface IDbContextConfig
    {
        DbContextOptions Create();
    }
    /// <summary>
    /// 上下文配置
    /// </summary>
    public class DbContextConfig : IDbContextConfig
    {
        public DbContextConfig() : this("Server=.;Initial Catalog=LiAnPayFormal;User ID=sa;Password=123456;")
        {
        }
        public DbContextConfig(string connectionString)
        {
            ConnectionString = connectionString;
        }
        /// <summary>
        /// 连接字符串
        /// </summary>
        public static string ConnectionString { get; set; }

        /// <summary>
        /// 创建   实现
        /// </summary>
        /// <returns></returns>
        public static DbContextOptions CreateDbContext(string connectionString)
        {
            ConnectionString = connectionString;
            return CreateDbContext();
        }
        public static DbContextOptions CreateDbContext()
        {
            return new DbContextOptionsBuilder()
                    .UseSqlServer(ConnectionString)
                    //.UseMySQL(connectionString)
                    .Options
                ;
        }

        public DbContextOptions Create()
        {
            return CreateDbContext();
        }
    }

}
